package org.advanced.security;

/**
 * @author John.zhang
 * @version Id: Visible, v 1.0 2020/12/8 17:46 ZhiYong Exp $
 * 读写屏障来保证可见性
 */
public class Visible {

    public volatile static boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            int i = 0;
            while (!stop) {
                i++;
            }
        });
        thread.start();
        Thread.sleep(1000);
        stop = true;
    }

}
